
data<-read.csv("figure9.csv",header=T,as.is=T)
# pid3
data$pid3 <-NA
data$pid3[data$Q4.3==1] =1
data$pid3[data$Q4.3==2] =2
data$pid3[data$Q4.3>=3] =3
data$pid3 = factor(data$pid3 , labels=c("Republican","Democrat","Independent"))
prop.table(table(data$pid3))

df <- read.csv(text="col1,col2")

#age
df<-rbind(df,cbind("Age",round(mean(data$Q1.4+17),digits=2)))
#male
df<-rbind(df,cbind("Male",round(prop.table(table(data$Q1.5))[[1]]*100,digits=2)))
#>college
df<-rbind(df,cbind(">College",round(prop.table(table(data$Q1.6>=7))[[2]]*100,digits=2)))
#white
df<-rbind(df,cbind("White",round(prop.table(table(data$Q1.8==4))[[2]]*100,digits=2)))
#ideology
df<-rbind(df,cbind("Ideology",round(mean(data$Q4.8),digits=2)))
names(df)<-c("Variable"," ")
print(xtable(df),include.rownames=FALSE)


data$bi<- factor(data$bi, labels=c("Bipartisan","Not Bipartisan"))
data$floor2 <- factor(data$floor2, labels=c("Not Overtly Partisan","Overtly Partisan"))

############
# Figure 9A
############

data$dv<-data$Q83
se <- function(x) sd(x, na.rm=T)/sqrt(length(na.omit(x)))
results<- ddply(.data = data, .variables = .(bi,floor2), .fun = summarise, 
				mean = mean(dv, na.rm=T),
				lower = mean(dv, na.rm=T) - (1.96*se(dv)),
				upper = mean(dv, na.rm=T) + (1.96*se(dv)),
				N = length(na.omit(dv)))

(results<-na.omit(results))

k<- qplot(bi,mean,data=results,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	scale_y_continuous(limits = c(4, 7))+
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("A) Support for legislation") + 
	coord_flip() +
	facet_grid(.~floor2)
k

ggsave(filename="f9a.eps", plot=k,width=5,height=2)


t.test(data$dv[data$bi=="Bipartisan" & data$floor2=="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan"& data$floor2=="Not Overtly Partisan"])
5.245954692556634 - 4.893835616438357 

t.test(data$dv[data$bi=="Bipartisan" & data$floor2!="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan" & data$floor2!="Not Overtly Partisan"])
4.750000000000000 - 4.465116279069767 


prop.table(table(data$dv[data$bi=="Not Bipartisan"]))
prop.table(table(data$dv[data$bi=="Bipartisan"]))

############
# Figure 9B
############
#ideology

data$dv<-abs(data$Q84-4)
se <- function(x) sd(x, na.rm=T)/sqrt(length(na.omit(x)))
results<- ddply(.data = data, .variables = .(bi,floor2), .fun = summarise, 
				mean = mean(dv, na.rm=T),
				lower = mean(dv, na.rm=T) - (1.96*se(dv)),
				upper = mean(dv, na.rm=T) + (1.96*se(dv)),
				N = length(na.omit(dv)))

(results<-na.omit(results))

k<- qplot(bi,mean,data=results,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	scale_y_continuous(limits = c(0, 2))+
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("B) Absolute distance from Ideological Midpoint") + 
	coord_flip() +
	facet_grid(.~floor2)
k

ggsave(filename="f9b.eps", plot=k,width=5,height=2)

t.test(data$dv[data$bi=="Bipartisan" & data$floor2=="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan"& data$floor2=="Not Overtly Partisan"])
0.3527508090614886 -0.7054794520547946 

t.test(data$dv[data$bi=="Bipartisan" & data$floor2!="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan" & data$floor2!="Not Overtly Partisan"])
0.7335526315789473 - 0.8039867109634552 


# HET
library(stargazer)
data$pid3 <- relevel(data$pid3, "Independent")
data$bi <- factor(data$bi,levels(data$bi)[c(2,1)])
data$dv<-data$Q83
demsupp <- lm(dv~bi*floor2, data=data[data$pid3=="Republican",])
repsupp <- lm(dv~bi*floor2, data=data[data$pid3=="Democrat",])
data$dv<-abs(data$Q84-4)
demideo <- lm(dv~bi*floor2, data=data[data$pid3=="Republican",])
repideo <- lm(dv~bi*floor2, data=data[data$pid3=="Democrat",])

stargazer(demsupp, repsupp, demideo, repideo,
		  type = "latex", 
		  intercept.bottom = FALSE, 
		  keep.stat = c("rsq"), 
		  digits=2, 
		  star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
		  column.labels =  c("Support (Democrats)","Support (Republicans)", "Extremity (Democrats)", "Extremity (Republicans)"),
		  covariate.labels = c("Intercept", "Bipartisan Treatment", "Overtly Partisan Treatment", "Bipartisan Treatment X Overtly Partisan Treatment"))

data$dv<-data$Q83
demsupp <- lm(dv~bi*floor2, data=data[data$Q4.8<4,])
repsupp <- lm(dv~bi*floor2, data=data[data$Q4.8>4,])
data$dv<-abs(data$Q84-4)
demsupp <- lm(dv~bi*floor2, data=data[data$Q4.8<4,])
repsupp <- lm(dv~bi*floor2, data=data[data$Q4.8>4,])

stargazer(demsupp, repsupp, demideo, repideo,
		  type = "latex", 
		  intercept.bottom = FALSE, 
		  keep.stat = c("rsq"), 
		  digits=2, 
		  star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
		  column.labels =  c("Support (Liberals)","Support (Conservatives)", "Extremity (Liberals)", "Extremity (Conservatives)"),
		  covariate.labels = c("Intercept", "Bipartisan Treatment", "Overtly Partisan Treatment", "Bipartisan Treatment X Overtly Partisan Treatment"))

